package v3.object;



import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import log.LogUtil;

import org.apache.log4j.Logger;

import cfg.MapArgs;
import galaxy.obj.Point;

public class STcfg
{
	static Map<Integer,Integer> sin = new HashMap<Integer, Integer>();
	static Map<Integer,Integer> cos = new HashMap<Integer, Integer>();
	static Map<Integer,Integer> angle = new HashMap<Integer, Integer>();	
	String dataPath;
	public double rad45 = Math.toRadians(45);
	public Random rnd;
	private boolean enemyMove;
	private boolean fixPosition;
	private boolean generateRandomAmmount;
	private boolean verbose;
	int universeSize = 3000;
	protected int baseAmmount = 80;
	protected int enemyAmmount = 160;
	protected int starAmmount = 320;
	
	protected Logger log=LogUtil.getLog(this.getClass());

	public void setUp(String[] args)
	{
		
		loadStaicData();
		if(args==null)
		{
			System.out.println("!!! No Args");
			return;
		}
			
		MapArgs mapArg= new MapArgs(args);		

		enemyMove=mapArg.getBoolean("ENEMY_MOVE",true);
		log.info("ENEMY_MOVE = " + enemyMove);
		
		fixPosition=mapArg.getBoolean("FIX_POSITION",false);
		log.info("FIX_POSITION = " + fixPosition);
		
		generateRandomAmmount=mapArg.getBoolean("GENERATE_RANDOM_AMMONT",false);
		log.info("GENERATE_RANDOM_AMMONT = " + generateRandomAmmount);
		
		verbose=mapArg.getBoolean("VERBOSE",true);
		log.info("VERBOSE = " + verbose);

		universeSize=mapArg.getInt("UNIVERSE_SIZE",50);
		log.info("UNIVERSE_SIZE = " + universeSize);
		
		baseAmmount=mapArg.getInt("BASE",80);
		log.info("BASE = " + baseAmmount);		
		
		enemyAmmount=mapArg.getInt("ENEMY",160);
		log.info("ENEMY = " + enemyAmmount);		
		
		starAmmount=mapArg.getInt("STAR",320);
		log.info("STAR = " + starAmmount);		
				
		dataPath=mapArg.getString("DATA_HIPPARCOS","H:/WorkSpace/_Galaxy/src/hipparcos/data/");
		log.info("DATA_HIPPARCOS = " + dataPath);
		
		rnd=new Random();
	}

	private void loadStaicData()
	{
		angle.put(3, 180);
		angle.put(2, -135);
		angle.put(1, -90);
		angle.put(8, -45);
		angle.put(7, 0);
		angle.put(6, 45);
		angle.put(5, 90);
		angle.put(4, 135);

		sin.put(3, 0);
		sin.put(2, 1);
		sin.put(1, 1);
		sin.put(8, 1);
		sin.put(7, 0);
		sin.put(6, -1);
		sin.put(5, -1);
		sin.put(4, -1);
		

		cos.put(3, 1);
		cos.put(2, 1);
		cos.put(1, 0);
		cos.put(8, -1);
		cos.put(7, -1);
		cos.put(6, -1);
		cos.put(5, 0);
		cos.put(4, 1);
		
//		for(int i =0; i<8;i++)
//			sin.put(i+1, (int) Math.round(Math.sin(Math.toRadians(i*45.))));
		
//		for(int i =0; i<8;i++)
//			cos.put(i+1, (int) Math.round(Math.cos(Math.toRadians(i*45.))));
		
	}
	
	public static double sin(int a)
	{
		return sin.get(a);
	}

	
	public static double cos(int a)
	{
		return cos.get(a);
	}
	

	public static Point getNewPosition(Point shipPosition, int cursor, double radius)
	{
		if(cursor==0)
			return shipPosition;
		
		double y = sin(cursor) * radius;
		double x = -cos(cursor) * radius;
		//System.out.println(TextUtil.append("x=",x,"/ty=",y));
		Point vector = new Point(x, y, 0);
		Point newPos = shipPosition.sub(vector);
		return newPos;		
	}

	public boolean isEnemyMove()
	{
		return enemyMove;
	}

	public void setEnemyMove(boolean enemyMove)
	{
		this.enemyMove = enemyMove;
	}

	public static int checkCursor(int cursor) throws Exception
	{
		if (cursor<1 || cursor>8)
			throw(new Exception());
		
		return cursor;
	}

	public boolean isFixPosition()
	{
		return fixPosition;
	}

	public void setFixPosition(boolean fixPosition)
	{
		this.fixPosition = fixPosition;
	}

	public boolean isGenerateRandomAmmount()
	{
		return generateRandomAmmount;
	}

	public void setGenerateRandomAmmount(boolean generateRandomAmmount)
	{
		this.generateRandomAmmount = generateRandomAmmount;
	}

	public String getDataPath()
	{
		return dataPath;
	}

	public void setDataPath(String dataPath)
	{
		this.dataPath = dataPath;
	}

	public int getBaseAmmount()
	{
		return baseAmmount;
	}

	public void setBaseAmmount(int baseAmmount)
	{
		this.baseAmmount = baseAmmount;
	}

	public int getEnemyAmmount()
	{
		return enemyAmmount;
	}

	public void setEnemyAmmount(int enemyAmmount)
	{
		this.enemyAmmount = enemyAmmount;
	}

	public int getStarAmmount()
	{
		return starAmmount;
	}

	public void setStarAmmount(int starAmmount)
	{
		this.starAmmount = starAmmount;
	}

	public int getUniverseSize()
	{
		return universeSize;
	}

	public void setUniverseSize(int universeSize)
	{
		this.universeSize = universeSize;
	}

	public boolean isVerbose()
	{
		return verbose;
	}

	public void setVerbose(boolean verbose)
	{
		this.verbose = verbose;
	}

	public boolean isSimulation3D()
	{
		return false;
	}
	
	
	
}
